﻿using Microsoft.AspNetCore.Diagnostics;
using Vin.Extension.Exception;
using Vin.Tool.Domain.ExceptionModel;

namespace SugarTest.Handler;

public class ErrorExceptionHandler : IExceptionHandler
{
    public async ValueTask<bool> TryHandleAsync(HttpContext httpContext, System.Exception exception, CancellationToken cancellationToken)
    {
        if (exception is not ErrorException errorException) return false;
        
        await ExceptionTool.HandleExceptionAsync(httpContext, errorException.Code,
            errorException.Message ?? "请联系管理员", errorException.StackTrace);
        
        return true;
    }
}